﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using zhangmenren.IService;
using zhangmenren.Models;
using zhangmenren.Models.Enums;

namespace zhangmenren.Untils
{
    public class GetData
    {
   
        public static  async Task<IEnumerable<BannerEntity>> GetBanner(IBannerService bannerService, ICacheService cacheService,string key, BannerType type)
        {
            IEnumerable<BannerEntity> list;
            if (cacheService.Exists(key))
            {
                var chche = cacheService.Get(key);
                if (chche != null)
                {
                    return (IEnumerable<BannerEntity>)chche;
                }
            }
            list = await bannerService.Find(type);
            if (list.Any())
            {
                cacheService.Add(key, list);
            }
            return list;
        }




    }
}
